<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class User extends Model
{

    public function role(){
        return $this->hasMany(UserRole::class,'uid','id');
    }
    //
    public function company(){
        return $this->belongsTo(Company::class,'company_id','id');
    }

    public function team(){
        return $this->belongsTo(SalesManTeam::class,'team_id','id');
    }

    public function invite(){
        return $this->belongsTo(User::class,'invite_uid','id');
    }

    public function info(){
        return $this->hasOne('UserInfo', 'id', 'user_id');
    }

    public static function changePhone($phone){
        $old = getUid(2);
        $res = self::where(['phone'=>$old])->find();
        if(!$res) return false;
        $r = $res->save(['phone'=>$phone]);

        return $r ? true :false;
    }
}
